
#include "Paineis/PainelD.h"
#include "PetLab.h"


PainelD::PainelD(int cx, int cy, int x, int y)
    : Controle(cx, cy, x, y)
{
    for(int i=0; i<Largura(); i++)
        for(int j=0; j<Altura(); j++)
        {
            int raio = Largura();
            int x = i - Largura()/2;
            int y = j - Altura()/2;
			double fator = ((double)::sqrt((float)x*x+y*y))/(raio);
            
            int r = (int)(fator * 64/2)+128+32;
            int g = (int)(fator * 64/2)+128+64+32;
            int b = 255;
            Matriz()[i][j] = RGBA(r,g,b,64);
        }
    
    for(int i=0; i<Largura(); i++)
    {
        Matriz()[i][0]          = RGBA(128,255,128+64+32,128+64);
        Matriz()[i][Altura()-1] = RGBA(128,255,128+64+32,128+64);
    }
    for(int j=0; j<Altura(); j++)
    {
        Matriz()[0][j]           = RGBA(128,255,128+64+32,128+64);
        Matriz()[Largura()-1][j] = RGBA(128,255,128+64+32,128+64);
    }

    Matriz()[0][0] &= 0x00FFFFFF;
    Matriz()[0][Altura()-1] &= 0x00FFFFFF;
    Matriz()[Largura()-1][0] &= 0x00FFFFFF;
    Matriz()[Largura()-1][Altura()-1] &= 0x00FFFFFF;
    
    
/*    
    // Adiciona TELA_A

    m_TelaA = new TelaA(5, 27);
    m_TelaA->Visivel(false);
    //m_TelaA->Abrir();
    m_TelaA->CarregarFuncao(NULL);
    this->AdicionarControle(m_TelaA);

    m_BotaoRe = new BotaoRe(0,0,&TelaA::ParteRe,m_TelaA);
    this->AdicionarControle(m_BotaoRe);

    m_BotaoIm = new BotaoIm(0,0,&TelaA::ParteIm,m_TelaA);
    this->AdicionarControle(m_BotaoIm);
*/

    m_OsciD = new OsciD(10,10+20);
    m_OsciD->Visivel(true);
    m_OsciD->DominioDCT();
    this->AdicionarControle(m_OsciD);
}


void PainelD::Redimensionar(int cx, int cy)
{
    Largura(cx);
    Altura(cy);
    
    for(int i=0; i<Largura(); i++)
        for(int j=0; j<Altura(); j++)
        {
            int raio = Largura();
            int x = i - Largura()/2;
            int y = j - Altura()/2;
			double fator = ((double)::sqrt((float)x*x+y*y))/(raio);
            
            int r = (int)(fator * 64/2)+128+32;
            int g = (int)(fator * 64/2)+128+64+32;
            int b = 255;
            Matriz()[i][j] = RGBA(r,g,b,64);
        }
    
    for(int i=0; i<Largura(); i++)
    {
        Matriz()[i][0]          = RGBA(128,255,128+64+32,128+64);
        Matriz()[i][Altura()-1] = RGBA(128,255,128+64+32,128+64);
    }
    for(int j=0; j<Altura(); j++)
    {
        Matriz()[0][j]           = RGBA(128,255,128+64+32,128+64);
        Matriz()[Largura()-1][j] = RGBA(128,255,128+64+32,128+64);
    }

    Matriz()[0][0] &= 0x00FFFFFF;
    Matriz()[0][Altura()-1] &= 0x00FFFFFF;
    Matriz()[Largura()-1][0] &= 0x00FFFFFF;
    Matriz()[Largura()-1][Altura()-1] &= 0x00FFFFFF;
}


bool PainelD::AoBaixarEsq(EventoBaixarEsq ev)
{
    return false;
    
    
    for(int i=0; i<Largura(); i++)
        for(int j=0; j<Altura(); j++)
        {
            int raio = Largura();
            int x = i - Largura()/2;
            int y = j - Altura()/2;
			double fator = ((double)::sqrt((float)x*x+y*y))/(raio);
            
            int r = (int)(fator * 64/2)+128+64+32;
            int g = (int)(fator * 64/2)+128+32;
            int b = 32;
            Matriz()[i][j] = RGBA(r,g,b,128);
        }
    
    for(int i=0; i<Largura(); i++)
    {
        Matriz()[i][0]          = RGBA(255,255,0/*128+64+32*/,255);
        Matriz()[i][Altura()-1] = RGBA(255,255,0/*128+64+32*/,255);
    }
    for(int j=0; j<Altura(); j++)
    {
        Matriz()[0][j]           = RGBA(255,255,0/*128+64+32*/,255);
        Matriz()[Largura()-1][j] = RGBA(255,255,0/*128+64+32*/,255);
    }

    Matriz()[0][0] &= 0x00FFFFFF;
    Matriz()[0][Altura()-1] &= 0x00FFFFFF;
    Matriz()[Largura()-1][0] &= 0x00FFFFFF;
    Matriz()[Largura()-1][Altura()-1] &= 0x00FFFFFF;
    
    ev.janela->Redesenhar(this);
}


bool PainelD::AoSubirEsq(EventoSubirEsq ev)
{
    return false;


    for(int i=0; i<Largura(); i++)
        for(int j=0; j<Altura(); j++)
        {
            int raio = Largura();
            int x = i - Largura()/2;
            int y = j - Altura()/2;
			double fator = ((double)::sqrt((float)x*x+y*y))/(raio);
            
            int r = (int)(fator * 64/2)+128+32;
            int g = (int)(fator * 64/2)+128+64+32;
            int b = 255;
            Matriz()[i][j] = RGBA(r,g,b,64);
        }
    
    for(int i=0; i<Largura(); i++)
    {
        Matriz()[i][0]          = RGBA(128,255,128+64+32,128+64);
        Matriz()[i][Altura()-1] = RGBA(128,255,128+64+32,128+64);
    }
    for(int j=0; j<Altura(); j++)
    {
        Matriz()[0][j]           = RGBA(128,255,128+64+32,128+64);
        Matriz()[Largura()-1][j] = RGBA(128,255,128+64+32,128+64);
    }

    Matriz()[0][0] &= 0x00FFFFFF;
    Matriz()[0][Altura()-1] &= 0x00FFFFFF;
    Matriz()[Largura()-1][0] &= 0x00FFFFFF;
    Matriz()[Largura()-1][Altura()-1] &= 0x00FFFFFF;
    
    ev.janela->Redesenhar(this);
}
